package com.vhall.component.plugin.core.service.event;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.context.ApplicationEvent;

/**
 * PAAS消息事件
 *
 * @author yuanzh
 * @date 2021/9/14
 */
@Getter
@Setter
@ToString
public class PaasMessageEvent extends ApplicationEvent {

    private static final long serialVersionUID = 3351360802463219247L;

    private PaasMessageReqDTO paasMessageReq;

    public PaasMessageEvent(Object source) {
        super(source);
    }

    public PaasMessageEvent(Object source, PaasMessageReqDTO paasMessageReq) {
        super(source);
        this.paasMessageReq = paasMessageReq;
    }

    public static class Builder {

        private final PaasMessageEvent event;

        /**
         * 构建事件
         *
         * @param source  事件源
         * @param channel 消息频道ID
         * @param body    消息体
         */
        public Builder(Object source, String channel, String body) {
            PaasMessageReqDTO paasMessageReq = new PaasMessageReqDTO.Builder(channel, body).initDefault().build();
            this.event = new PaasMessageEvent(source, paasMessageReq);
        }

        public PaasMessageEvent build() {
            return this.event;
        }
    }

}
